package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/8.
 */
@HttpInlet(Conn.ACTIVE_GET)
public class ProjectListGet extends BaseAsyGet<ProjectListGet.ProjectEntity> {


    public ProjectListGet(AsyCallBack<ProjectEntity> asyCallBack) {
        super(asyCallBack);
    }


    @Override
    protected ProjectEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            JSONArray array = object.optJSONArray("data");

            ProjectEntity projectEntity = new ProjectEntity();

            for (int i = 0; i < array.length(); i++) {


                JSONObject entityObject = array.optJSONObject(i);

                Project p = new Project();

                p.id = entityObject.optString("id");
                p.title = entityObject.optString("title");
                p.picurl = Conn.IMAGE_BANNER_URL + entityObject.optString("picurl");
                p.price = entityObject.optString("price");
                p.intro = entityObject.optString("intro");
                p.starttime = entityObject.optString("starttime");
                p.endtime = entityObject.optString("endtime");
                p.step = entityObject.optString("step");



                p.type = entityObject.optString("type");
                p.weburl = entityObject.optString("weburl");



                projectEntity.projectList.add(p);


            }

            return projectEntity;
        }

        return null;
    }

    public static class ProjectEntity {

        public List<Project> projectList = new ArrayList<>();

    }

    public static class Project {


        public String id, title, picurl, price, intro, starttime, endtime, step,type,weburl;

    }

}
